package top.codedance.iotp.server.net.handle.subhandle.controller.http.sync;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import top.codedance.iotp.server.ServerApplication;
import top.codedance.iotp.server.net.TcpServer;
import top.codedance.iotp.server.net.handle.subhandle.controller.AdapterController;
import org.apache.log4j.Logger;

public class RegistedClientsController extends AdapterController {

    private static Logger logger = ServerApplication.getLogger(RegistedClientsController.class);

    public String doSubHandler(JSONObject body) {
        try {
            if (!adminVerification()) {
                return response403("No access");
            }
            String[] clientDeviceIds = TcpServer.sessionManager.getClientDeviceIds();
            JSONArray jsonArray = new JSONArray();
            for (int i = 0; i < clientDeviceIds.length; i++) {
                jsonArray.add(clientDeviceIds[i]);
            }
            return okResponse(jsonArray);
        }catch (Exception e){
            return response500("Programe exception");
        }
    }
}
